<!--
 * @Description:键盘控制文字发布
 * @Author: Sun
 * @Date: 2019-07-01 20:05:50
 * @LastEditors: Sun
 * @LastEditTime: 2019-07-07 20:53:15
 -->
<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>键盘控制文字发布</title>
	<style>
		#div1 {
			width: 100px;
			height: 100px;
			background: #ccc;
			position: absolute;
		}
	</style>

</head>
<script>
	window.onload = function () {

		document.onkeydown = function (ev) {
			var oTxt1 = document.getElementById('txt1')
			var oTxt2 = document.getElementById('txt2')
			var oBtn = document.getElementById('btn1')

			var oEvent = ev || event
			console.log(ev.keyCode)

			oBtn.onclick=function(){
				oTxt2.value+=oTxt1.value+'\n';
				oTxt1.value='';


			}


			// if(oEvent.keyCode==37){
			// 	oDiv.style.left=oDiv.offsetLeft-10+'px';
			// }else if(oEvent.keyCode==39){
			// 	oDiv.style.left=oDiv.offsetLeft+10+'px';
			// }

		}

	}
</script>

<body>
	<div>
		keyCode 键盘事件 获取用户按下的那个键<br>
		onkeydown 按键按下<br>
		onkeyup  按键抬起
	</div>
	<input id="txt1" type="text"/>
	<input id="btn1" type="button" value="发布"><br>
	<textarea id="txt2" rows="10" cols="40"></textarea>

</body>

</html>